# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: Rasmus Thomsen <oss@cogitri.dev>
pkgname=gtk4.0
pkgver=3.99.0
pkgrel=0
pkgdesc="The GTK Toolkit (v4)"
url="https://www.gtk.org/"
install="$pkgname.post-install $pkgname.post-upgrade $pkgname.post-deinstall"
arch="all !x86 !armhf !armv7" # Needs >4GB when compiling
arch="$arch !mips64" # Limited by ilmbase
options="!check"  # Test suite is known to fail upstream
license="LGPL-2.1-or-later"
subpackages="$pkgname-demo $pkgname-dev $pkgname-doc $pkgname-lang $pkgname-dbg"
depends="shared-mime-info gtk-update-icon-cache"

depends_dev="
	atk-dev
	gdk-pixbuf-dev
	glib-dev
	libepoxy-dev
	libxext-dev
	libxi-dev
	libxinerama-dev
	wayland-protocols
	wayland-libs-client
	wayland-libs-cursor
	libxkbcommon-dev
	vulkan-headers<1.2.140
	"
makedepends="
	$depends_dev
	perl
	cups-dev
	expat-dev
	gettext-dev
	gnutls-dev
	gobject-introspection-dev
	libice-dev
	tiff-dev
	zlib-dev
	at-spi2-atk-dev
	cairo-dev
	fontconfig-dev
	pango-dev
	wayland-dev
	libx11-dev
	libxcomposite-dev
	libxcursor-dev
	libxdamage-dev
	libxfixes-dev
	libxrandr-dev
	meson
	iso-codes-dev
	vulkan-loader-dev
	sassc
	colord-dev
	gstreamer-dev
	gst-plugins-bad-dev
	gtk-doc
	graphene-dev
	"
source="https://download.gnome.org/sources/gtk/${pkgver%.*}/gtk-$pkgver.tar.xz"


builddir="$srcdir/gtk-$pkgver"

build() {
	# We don't run tests and they currently fail to build
	meson \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--buildtype=plain \
		-Dbroadway-backend=true \
		-Dman-pages=true \
		-Ddocumentation=true \
		-Dbuild-tests=false \
		. output
	ninja -C output
}

package() {
	DESTDIR="$pkgdir" ninja -C output install

	# use gtk-update-icon-cache from gtk+2.0 for now. The icon cache is forward
	# compatible so this is fine
	rm -f "$pkgdir"/usr/bin/gtk-update-icon-cache
	rm -f "$pkgdir"/usr/share/man/man1/gtk-update-icon-cache.1
}

demo() {
	pkgdesc="$pkgdesc (demonstration application)"
	install -Dm755 "$pkgdir"/usr/bin/gtk4-demo \
				   "$pkgdir"/usr/bin/gtk4-widget-factory \
				   "$pkgdir"/usr/bin/gtk4-demo-application \
				   -t "$subpkgdir"/usr/bin
	install -Dm644 "$pkgdir"/usr/share/gtk-4.0/gtk4builder.rng \
				   -t "$subpkgdir"/usr/share/gtk-4.0
	install -Dm644 "$pkgdir"/usr/share/glib-2.0/schemas/org.gtk.Demo4.gschema.xml \
				   -t "$subpkgdir"/usr/share/glib-2.0/schemas
	install -Dm644 "$pkgdir"/usr/share/applications/org.gtk.WidgetFactory4.desktop \
				   "$pkgdir"/usr/share/applications/org.gtk.Demo4.desktop \
				   -t "$subpkgdir"/usr/share/applications
	mkdir -p "$subpkgdir"/usr/share
	mv "$pkgdir"/usr/share/icons "$subpkgdir"/usr/share
}

sha512sums="da720499bce5bb6eca7d51175829262560bafd24d041c72ed5a9201643434977e7f7ab624eb1b01b482870b06900aec6bd2cc33aa987b801c45a0778f8278051  gtk-3.99.0.tar.xz"
